<template>
	<view>
		<view class="icon_div">
			<image class="luncher_img" src="../../static/ic_launcher.png"></image>
		</view>

		<view class="list_div">
			<view class="item_div">
				<text class="left_text">版本信息</text>
				<text class="right_text">v{{version_number}}</text>
			</view>

			<navigator class="item_div" url="../resetPwd/resetPwd">
				<text class="left_text">修改密码</text>
				<image class="right_img" src="../../static/sobot_right_arrow_icon.png"></image>
			</navigator>

			<view class="item_div" @tap="clearStorage()">
				<text class="left_text">清空缓存</text>
				<text class="right_text">{{storageSize}}</text>
				<image class="right_img" src="../../static/sobot_right_arrow_icon.png"></image>
			</view>

		</view>
		<view class="btn_div">
			<button class="btn" @tap="exit()">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				storageSize: '', //缓存
				version_number: '', //版本号
			}
		},
		onLoad() {
			this.getStorageSize();
			var that=this;
			 const res = uni.getSystemInfoSync();
			  this.version_number=res.version;
			  
		},
		methods: {
			getStorageSize: function() {
				let that = this;
				uni.getStorageInfo({
					success(res) {
						//console.log(res.keys);
						//console.log(res.limitSize);
						let size = res.currentSize;
						if (size < 1024) {
							that.storageSize = size + ' B';
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							that.storageSize = Math.floor(size / 1024 * 100) / 100 + ' KB';
						} else if (size / 1024 / 1024 >= 1) {
							that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + ' M';
						}
					}
				})
			},
			clearStorage: function() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定清除缓存吗?',
					confirmText: '立即清除',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync();
							//重新获取并显示清除后的缓存大小
							that.getStorageSize();
							uni.showToast({
								title: '清除成功'
							})
						}
					}
				})
			},
			exit: function() {
				uni.clearStorageSync();//清空本地缓存
				uni.navigateTo({
					url: '../login/login' //跳转到登录
				});
					
				
			}
		}
	}
</script>

<style>
	.icon_div {
		text-align: center;
	}

	.icon_div .luncher_img {
		width: 210rpx;
		height: 210rpx;
		margin-top: 50rpx;
		margin-bottom: 60rpx;
	}

	.list_div {
		background: #FFFFFF;
		border-top: 1rpx solid #DADADA;
	}

	.list_div .item_div {
		height: 96rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 25rpx;
		padding-right: 25rpx;
		font-size: 28rpx;
		color: #333333;
		border-bottom: 1rpx solid #E8E8E8;
	}

	.list_div .item_div .left_text {
		color: #666666;
		flex: 1;
	}

	.list_div .item_div .right_img {
		width: 13rpx;
		height: 26rpx;
		margin-left: 10rpx;
	}

	.btn_div {
		height: 96rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		margin-top: 40rpx;
	}

	.btn_div .btn {
		font-size: 28rpx;
		color: #d5212e;
		height: 88rpx;
		line-height: 88rpx;
		border-radius: 10rpx;
		background: #FFFFFF;
		border: 1rpx solid #E8E8E8;
	}
</style>
